Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add special handling for comparisons with Singleton types #20474

Merged
merged 1 commit into from
May 28, 2024

Conversation

odersky
Copy link
Contributor

@odersky odersky commented May 26, 2024

Fixes #15030

@odersky odersky marked this pull request as ready for review May 27, 2024 11:43
@odersky odersky requested a review from smarter May 27, 2024 11:43
@odersky odersky assigned odersky and smarter and unassigned odersky May 27, 2024
Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but this might need equivalent handling in tasty-query /cc @sjrd

@smarter smarter merged commit 9b5ab2e into scala:main May 28, 2024
19 checks passed
@smarter smarter deleted the fix-15030 branch May 28, 2024 13:40
@noti0na1
Copy link
Member

noti0na1 commented May 28, 2024

I don't think the rule in this PR is correct:

class A
class B extends A

def f(a: A, c: A) =
  val b1: a.type = a
  val b2: a.type & B = a.asInstanceOf[a.type & B]
  val b3: c.type & A = c
  val b4: a.type | c.type = c

  val d1: b1.type = a
  val d2: b2.type = a // ok
  val d3: b3.type = a // error
  val d4: b4.type = a // error

In 3.4.2:

> scala-cli compile -S 3.4 Stest.scala
Compiling project (Scala 3.4.2, JVM (21))
[error] ./Stest.scala:324:21
[error] Found:    (a : A)
[error] Required: (b3 : (c : A) & A)
[error]   val d3: b3.type = a // error
[error]                     ^
[error] ./Stest.scala:325:21
[error] Found:    (a : A)
[error] Required: (b4 : (a : A) | (c : A))
[error]   val d4: b4.type = a // error
[error]                     ^
Error compiling project (Scala 3.4.2, JVM (21))
Compilation failed

cc @sjrd

odersky added a commit to dotty-staging/dotty that referenced this pull request May 28, 2024
As usual, OrTypes need to be excluded. a.type | b.type is not effectively a
singleton. It seems to be an easy trap to fall into.

Follow-up to scala#20474
noti0na1 added a commit that referenced this pull request May 28, 2024
As usual, OrTypes need to be excluded. a.type | b.type is not
effectively a singleton. It seems to be an easy trap to fall into.

Follow-up to #20474
@Kordyjan Kordyjan added this to the 3.5.1 milestone Jul 3, 2024
WojciechMazur pushed a commit that referenced this pull request Jul 8, 2024
As usual, OrTypes need to be excluded. a.type | b.type is not effectively a
singleton. It seems to be an easy trap to fall into.

Follow-up to #20474

[Cherry-picked d04005c]
WojciechMazur added a commit that referenced this pull request Jul 9, 2024
…to LTS (#21126)

Backports #20474 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants